package CronRequest

import (
	"arabApi/app/api/requests"
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

// TpCronJob  z定时任务管理表
type CronJob struct {
	ID    int64  `json:"id"`
	Name  string `json:"name"  valid:"name"` //  标签
	Spec  string `json:"spec"  valid:"spec"` //  规则
	Desc  string `json:"desc"`               //  描述
	JobId int64  `json:"job_id" valid:"-"`   //  任务id
	State int64  `json:"state"`              //  1 开启 2 禁用
}

func CheckCron(data interface{}, c *gin.Context) string {
	// 自定义验证规则
	rules := govalidator.MapData{
		"name": []string{"required"},
		"spec": []string{"required"},
	}
	// 自定义验证出错时的提示
	messages := govalidator.MapData{
		"name": []string{
			"required:定时任务名称不能为空",
		},
		"spec": []string{
			"required:定时任务规则不能为空",
		},
	}

	errs := requests.Validate1(data, rules, messages)
	return requests.GetOneErr(errs)
}
